home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / os2 / adaptor.zip / ADAPT.ZIP / adaptor / src / expressi.c < prev    next >
Text File  |  1994-01-03  |  27KB  |  1,317 lines

  1. # include "Expressi.h"
  2. # include "yyExpres.w"
  3. # include <stdio.h>
  4. # if defined __STDC__ | defined __cplusplus
  5. #  include <stdlib.h>
  6. # else
  7.    extern void exit ();
  8. # endif
  9. # include "Tree.h"
  10. # include "Definiti.h"
  11.  
  12. # ifndef NULL
  13. # define NULL 0L
  14. # endif
  15. # ifndef false
  16. # define false 0
  17. # endif
  18. # ifndef true
  19. # define true 1
  20. # endif
  21.  
  22. # ifdef yyInline
  23. # define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) \
  24.   if ((ptr = (tree) free) >= (tree) max) ptr = alloc (); \
  25.   free += nodesize [kind]; \
  26.   ptr->yyHead.yyMark = 0; \
  27.   ptr->Kind = kind;
  28. # else
  29. # define yyALLOC(tree, free, max, alloc, nodesize, make, ptr, kind) ptr = make (kind);
  30. # endif
  31.  
  32. # define yyWrite(s) (void) fputs (s, yyf)
  33. # define yyWriteNl (void) fputc ('\n', yyf)
  34.  
  35. # line 37 "Expressions.puma"
  36.  
  37. # include "Tree.h"
  38. # include "Idents.h"
  39. # include "StringMe.h"
  40.  
  41. # include "protocol.h"
  42.  
  43. # include "Definiti.h"
  44.  
  45. int power (base, n)
  46. int base, n;
  47. { int i, p;
  48.  
  49.   p = 1;
  50.   for (i=1; i<=n; ++i)
  51.      p = p * base;
  52.   return p;
  53. }
  54.  
  55.  
  56.  
  57. static FILE * yyf = stdout;
  58.  
  59. static void yyAbort
  60. # ifdef __cplusplus
  61.  (char * yyFunction)
  62. # else
  63.  (yyFunction) char * yyFunction;
  64. # endif
  65. {
  66.  (void) fprintf (stderr, "Error: module Expressions, routine %s failed\n", yyFunction);
  67.  exit (1);
  68. }
  69.  
  70. void GetIntConstValue ARGS((tTree exp, bool * found, int * val));
  71. void GetConstDifference ARGS((tTree exp1, tTree exp2, bool * found, int * val));
  72. void ResolveExpression ARGS((tTree exp, bool * found, int * a, int * b, tTree * var));
  73. static void MergeVars ARGS((int a1, tTree v1, int a2, tTree v2, bool * ok, tTree * var));
  74. bool EqualExpression ARGS((tTree e1, tTree e2));
  75. int IsVarInExp ARGS((tIdent name, tTree exp));
  76. tTree MakeNotExp ARGS((tTree e));
  77. void SliceIncrement ARGS((tTree yyP1, bool * yyP3, int * yyP2));
  78. tTree MakeSliceExp ARGS((tTree start, tTree stop));
  79. tTree AddConstant ARGS((tTree exp, int c));
  80. tTree MakeConstant ARGS((int n));
  81.  
  82. void GetIntConstValue
  83. # if defined __STDC__ | defined __cplusplus
  84. (register tTree exp, register bool * found, register int * val)
  85. # else
  86. (exp, found, val)
  87.  register tTree exp;
  88.  register bool * found;
  89.  register int * val;
  90. # endif
  91. {
  92.  
  93.   switch (exp->Kind) {
  94.   case kOP_EXP:
  95.   if (exp->OP_EXP.EXP_OP->Kind == kOP_PLUS) {
  96. # line 69 "Expressions.puma"
  97.  {
  98.   bool yyV1;
  99.   int yyV2;
  100.   bool yyV3;
  101.   int yyV4;
  102.   {
  103. # line 70 "Expressions.puma"
  104.    GetIntConstValue (exp->OP_EXP.OPND1, & yyV1, & yyV2);
  105. # line 71 "Expressions.puma"
  106.    GetIntConstValue (exp->OP_EXP.OPND2, & yyV3, & yyV4);
  107.   }
  108.    * found = yyV1 && yyV3;
  109.    * val = yyV2 + yyV4;
  110.    return;
  111.  }
  112.  
  113.   }
  114.   if (exp->OP_EXP.EXP_OP->Kind == kOP_MINUS) {
  115. # line 74 "Expressions.puma"
  116.  {
  117.   bool yyV1;
  118.   int yyV2;
  119.   bool yyV3;
  120.   int yyV4;
  121.   {
  122. # line 75 "Expressions.puma"
  123.    GetIntConstValue (exp->OP_EXP.OPND1, & yyV1, & yyV2);
  124. # line 76 "Expressions.puma"
  125.    GetIntConstValue (exp->OP_EXP.OPND2, & yyV3, & yyV4);
  126.   }
  127.    * found = yyV1 && yyV3;
  128.    * val = yyV2 - yyV4;
  129.    return;
  130.  }
  131.  
  132.   }
  133.   if (exp->OP_EXP.EXP_OP->Kind == kOP_TIMES) {
  134. # line 79 "Expressions.puma"
  135.  {
  136.   bool yyV1;
  137.   int yyV2;
  138.   bool yyV3;
  139.   int yyV4;
  140.   {
  141. # line 80 "Expressions.puma"
  142.    GetIntConstValue (exp->OP_EXP.OPND1, & yyV1, & yyV2);
  143. # line 81 "Expressions.puma"
  144.    GetIntConstValue (exp->OP_EXP.OPND2, & yyV3, & yyV4);
  145.   }
  146.    * found = yyV1 && yyV3;
  147.    * val = yyV2 * yyV4;
  148.    return;
  149.  }
  150.  
  151.   }
  152.   if (exp->OP_EXP.EXP_OP->Kind == kOP_DIVIDE) {
  153. # line 84 "Expressions.puma"
  154.  {
  155.   bool yyV1;
  156.   int yyV2;
  157.   bool yyV3;
  158.   int yyV4;
  159.   {
  160. # line 85 "Expressions.puma"
  161.    GetIntConstValue (exp->OP_EXP.OPND1, & yyV1, & yyV2);
  162. # line 86 "Expressions.puma"
  163.    GetIntConstValue (exp->OP_EXP.OPND2, & yyV3, & yyV4);
  164. # line 87 "Expressions.puma"
  165.  if (yyV4 == 0)
  166.         { yyV3 = false;
  167.           yyV4   = 1;
  168.         }
  169.  
  170.   }
  171.    * found = yyV1 && yyV3;
  172.    * val = yyV2 / yyV4;
  173.    return;
  174.  }
  175.  
  176.   }
  177.   if (exp->OP_EXP.EXP_OP->Kind == kOP_EXPO) {
  178. # line 94 "Expressions.puma"
  179.  {
  180.   bool yyV1;
  181.   int yyV2;
  182.   bool yyV3;
  183.   int yyV4;
  184.   {
  185. # line 95 "Expressions.puma"
  186.    GetIntConstValue (exp->OP_EXP.OPND1, & yyV1, & yyV2);
  187. # line 96 "Expressions.puma"
  188.    GetIntConstValue (exp->OP_EXP.OPND2, & yyV3, & yyV4);
  189. # line 97 "Expressions.puma"
  190.  if (yyV4 < 0) yyV3 = false;
  191.   }
  192.    * found = yyV1 && yyV3;
  193.    * val = power (yyV2, yyV4);
  194.    return;
  195.  }
  196.  
  197.   }
  198.   break;
  199.   case kOP1_EXP:
  200.   if (exp->OP1_EXP.EXP_OP1->Kind == kOP1_SIGN) {
  201. # line 100 "Expressions.puma"
  202.  {
  203.   bool yyV1;
  204.   int yyV2;
  205.   {
  206. # line 101 "Expressions.puma"
  207.    GetIntConstValue (exp->OP1_EXP.OPND, & yyV1, & yyV2);
  208.   }
  209.    * found = yyV1;
  210.    * val = - yyV2;
  211.    return;
  212.  }
  213.  
  214.   }
  215.   break;
  216.   case kVAR_EXP:
  217. # line 104 "Expressions.puma"
  218.  {
  219.   bool yyV1;
  220.   int yyV2;
  221.   {
  222. # line 105 "Expressions.puma"
  223.    GetIntConstValue (exp->VAR_EXP.V, & yyV1, & yyV2);
  224.   }
  225.    * found = yyV1;
  226.    * val = yyV2;
  227.    return;
  228.  }
  229.  
  230.   case kUSED_VAR:
  231. # line 108 "Expressions.puma"
  232.   {
  233. # line 111 "Expressions.puma"
  234.    if (! (exp->USED_VAR.VARNAME->VAR_OBJ.Object == NoObject)) goto yyL8;
  235.   }
  236.    * found = false;
  237.    * val = 0;
  238.    return;
  239. yyL8:;
  240.  
  241.   if (exp->USED_VAR.VARNAME->VAR_OBJ.Object->Kind == kVarObject) {
  242.   if (exp->USED_VAR.VARNAME->VAR_OBJ.Object->VarObject.Kind->Kind == kVarConstant) {
  243. # line 114 "Expressions.puma"
  244.  {
  245.   bool yyV1;
  246.   int yyV2;
  247.   {
  248. # line 116 "Expressions.puma"
  249.    GetIntConstValue (exp->USED_VAR.VARNAME->VAR_OBJ.Object->VarObject.Kind->VarConstant.Val, & yyV1, & yyV2);
  250.   }
  251.    * found = yyV1;
  252.    * val = yyV2;
  253.    return;
  254.  }
  255.  
  256.   }
  257.   }
  258.   break;
  259.   case kVAR_PARAM:
  260. # line 119 "Expressions.puma"
  261.  {
  262.   bool yyV1;
  263.   int yyV2;
  264.   {
  265. # line 120 "Expressions.puma"
  266.    GetIntConstValue (exp->VAR_PARAM.V, & yyV1, & yyV2);
  267.   }
  268.    * found = yyV1;
  269.    * val = yyV2;
  270.    return;
  271.  }
  272.  
  273.   case kADDR:
  274. # line 123 "Expressions.puma"
  275.  {
  276.   bool yyV1;
  277.   int yyV2;
  278.   {
  279. # line 124 "Expressions.puma"
  280.    GetIntConstValue (exp->ADDR.E, & yyV1, & yyV2);
  281.   }
  282.    * found = yyV1;
  283.    * val = yyV2;
  284.    return;
  285.  }
  286.  
  287.   case kCONST_EXP:
  288.   if (exp->CONST_EXP.C->Kind == kINT_CONSTANT) {
  289. # line 127 "Expressions.puma"
  290.    * found = true;
  291.    * val = exp->CONST_EXP.C->INT_CONSTANT.value;
  292.    return;
  293.  
  294.   }
  295.   break;
  296.   }
  297.  
  298. # line 130 "Expressions.puma"
  299.    * found = false;
  300.    * val = 0;
  301.    return;
  302.  
  303. ;
  304. }
  305.  
  306. void GetConstDifference
  307. # if defined __STDC__ | defined __cplusplus
  308. (register tTree exp1, register tTree exp2, register bool * found, register int * val)
  309. # else
  310. (exp1, exp2, found, val)
  311.  register tTree exp1;
  312.  register tTree exp2;
  313.  register bool * found;
  314.  register int * val;
  315. # endif
  316. {
  317. # line 147 "Expressions.puma"
  318.   {
  319. # line 148 "Expressions.puma"
  320.    if (! (((exp1 == NoTree) || (exp2 == NoTree)))) goto yyL1;
  321.   {
  322. # line 149 "Expressions.puma"
  323.    printf ("Illegal Call of GetConstDifference with NoTree\n");
  324. # line 150 "Expressions.puma"
  325.    kill_in_protocol ();
  326.   }
  327.   }
  328.    * found = false;
  329.    * val = 0;
  330.    return;
  331. yyL1:;
  332.  
  333. # line 153 "Expressions.puma"
  334.   {
  335. # line 155 "Expressions.puma"
  336.    if (! ( EqualExpression (exp1, exp2 )  == true)) goto yyL2;
  337.   }
  338.    * found = true;
  339.    * val = 0;
  340.    return;
  341. yyL2:;
  342.  
  343. # line 158 "Expressions.puma"
  344.  {
  345.   bool yyV1;
  346.   int yyV2;
  347.   int yyV3;
  348.   tTree yyV4;
  349.   bool yyV5;
  350.   int yyV6;
  351.   int yyV7;
  352.   tTree yyV8;
  353.   bool yyV9;
  354.   tTree yyV10;
  355.   {
  356. # line 159 "Expressions.puma"
  357.    ResolveExpression (exp1, & yyV1, & yyV2, & yyV3, & yyV4);
  358. # line 160 "Expressions.puma"
  359.    if (! ((yyV1))) goto yyL3;
  360.   {
  361. # line 161 "Expressions.puma"
  362.    ResolveExpression (exp2, & yyV5, & yyV6, & yyV7, & yyV8);
  363. # line 162 "Expressions.puma"
  364.    if (! ((yyV5))) goto yyL3;
  365.   {
  366. # line 163 "Expressions.puma"
  367.    MergeVars (yyV2, yyV4, yyV6, yyV8, & yyV9, & yyV10);
  368. # line 164 "Expressions.puma"
  369.    if (! ((yyV9 == true))) goto yyL3;
  370.   {
  371. # line 165 "Expressions.puma"
  372.    if (! ((yyV2 == yyV6))) goto yyL3;
  373.   }
  374.   }
  375.   }
  376.   }
  377.    * found = true;
  378.    * val = yyV3 - yyV7;
  379.    return;
  380.  }
  381. yyL3:;
  382.  
  383.   if (exp1->Kind == kSLICE_EXP) {
  384.   if (exp2->Kind == kSLICE_EXP) {
  385. # line 168 "Expressions.puma"
  386.  {
  387.   bool yyV1;
  388.   int yyV2;
  389.   bool yyV3;
  390.   int yyV4;
  391.   {
  392. # line 170 "Expressions.puma"
  393.    GetConstDifference (exp1->SLICE_EXP.START, exp2->SLICE_EXP.START, & yyV1, & yyV2);
  394. # line 171 "Expressions.puma"
  395.    if (! ((yyV1 == true))) goto yyL4;
  396.   {
  397. # line 172 "Expressions.puma"
  398.    GetConstDifference (exp1->SLICE_EXP.STOP, exp2->SLICE_EXP.STOP, & yyV3, & yyV4);
  399. # line 173 "Expressions.puma"
  400.    if (! ((yyV3 == true))) goto yyL4;
  401.   {
  402. # line 174 "Expressions.puma"
  403.    if (! ((yyV2 == yyV4))) goto yyL4;
  404.   {
  405. # line 175 "Expressions.puma"
  406.    if (! (EqualExpression (exp1->SLICE_EXP.INC, exp2->SLICE_EXP.INC))) goto yyL4;
  407.   }
  408.   }
  409.   }
  410.   }
  411.    * found = true;
  412.    * val = yyV2;
  413.    return;
  414.  }
  415. yyL4:;
  416.  
  417.   }
  418.   }
  419. # line 178 "Expressions.puma"
  420.    * found = false;
  421.    * val = 0;
  422.    return;
  423.  
  424. ;
  425. }
  426.  
  427. void ResolveExpression
  428. # if defined __STDC__ | defined __cplusplus
  429. (register tTree exp, register bool * found, register int * a, register int * b, register tTree * var)
  430. # else
  431. (exp, found, a, b, var)
  432.  register tTree exp;
  433.  register bool * found;
  434.  register int * a;
  435.  register int * b;
  436.  register tTree * var;
  437. # endif
  438. {
  439. # line 203 "Expressions.puma"
  440.   {
  441. # line 204 "Expressions.puma"
  442.    if (! ((exp == NoTree))) goto yyL1;
  443.   {
  444. # line 205 "Expressions.puma"
  445.    printf ("Call of ResolveExpression with NoTree\n");
  446. # line 206 "Expressions.puma"
  447.    kill_in_protocol ();
  448.   }
  449.   }
  450.    * found = false;
  451.    * a = 0;
  452.    * b = 0;
  453.    * var = NoTree;
  454.    return;
  455. yyL1:;
  456.  
  457. # line 209 "Expressions.puma"
  458.  {
  459.   bool yyV1;
  460.   int yyV2;
  461.   {
  462. # line 210 "Expressions.puma"
  463.    GetIntConstValue (exp, & yyV1, & yyV2);
  464. # line 211 "Expressions.puma"
  465.    if (! ((yyV1))) goto yyL2;
  466.   }
  467.    * found = true;
  468.    * a = 0;
  469.    * b = yyV2;
  470.    * var = NoTree;
  471.    return;
  472.  }
  473. yyL2:;
  474.  
  475.  
  476.   switch (exp->Kind) {
  477.   case kOP_EXP:
  478.   if (exp->OP_EXP.EXP_OP->Kind == kOP_PLUS) {
  479. # line 214 "Expressions.puma"
  480.  {
  481.   bool yyV1;
  482.   int yyV2;
  483.   int yyV3;
  484.   tTree yyV4;
  485.   bool yyV5;
  486.   int yyV6;
  487.   int yyV7;
  488.   tTree yyV8;
  489.   bool yyV9;
  490.   tTree yyV10;
  491.   {
  492. # line 215 "Expressions.puma"
  493.    ResolveExpression (exp->OP_EXP.OPND1, & yyV1, & yyV2, & yyV3, & yyV4);
  494. # line 216 "Expressions.puma"
  495.    if (! ((yyV1))) goto yyL3;
  496.   {
  497. # line 217 "Expressions.puma"
  498.    ResolveExpression (exp->OP_EXP.OPND2, & yyV5, & yyV6, & yyV7, & yyV8);
  499. # line 218 "Expressions.puma"
  500.    if (! ((yyV5))) goto yyL3;
  501.   {
  502. # line 219 "Expressions.puma"
  503.    MergeVars (yyV2, yyV4, yyV6, yyV8, & yyV9, & yyV10);
  504. # line 220 "Expressions.puma"
  505.    if (! ((yyV9))) goto yyL3;
  506.   }
  507.   }
  508.   }
  509.    * found = true;
  510.    * a = yyV2 + yyV6;
  511.    * b = yyV3 + yyV7;
  512.    * var = yyV10;
  513.    return;
  514.  }
  515. yyL3:;
  516.  
  517.   }
  518.   if (exp->OP_EXP.EXP_OP->Kind == kOP_MINUS) {
  519. # line 223 "Expressions.puma"
  520.  {
  521.   bool yyV1;
  522.   int yyV2;
  523.   int yyV3;
  524.   tTree yyV4;
  525.   bool yyV5;
  526.   int yyV6;
  527.   int yyV7;
  528.   tTree yyV8;
  529.   bool yyV9;
  530.   tTree yyV10;
  531.   {
  532. # line 224 "Expressions.puma"
  533.    ResolveExpression (exp->OP_EXP.OPND1, & yyV1, & yyV2, & yyV3, & yyV4);
  534. # line 225 "Expressions.puma"
  535.    ResolveExpression (exp->OP_EXP.OPND2, & yyV5, & yyV6, & yyV7, & yyV8);
  536. # line 226 "Expressions.puma"
  537.    if (! ((yyV1 && yyV5))) goto yyL4;
  538.   {
  539. # line 227 "Expressions.puma"
  540.    MergeVars (yyV2, yyV4, yyV6, yyV8, & yyV9, & yyV10);
  541. # line 228 "Expressions.puma"
  542.    if (! ((yyV9))) goto yyL4;
  543.   }
  544.   }
  545.    * found = true;
  546.    * a = yyV2 - yyV6;
  547.    * b = yyV3 - yyV7;
  548.    * var = yyV10;
  549.    return;
  550.  }
  551. yyL4:;
  552.  
  553.   }
  554.   if (exp->OP_EXP.EXP_OP->Kind == kOP_TIMES) {
  555. # line 231 "Expressions.puma"
  556.  {
  557.   bool yyV1;
  558.   int yyV2;
  559.   bool yyV3;
  560.   int yyV4;
  561.   int yyV5;
  562.   tTree yyV6;
  563.   {
  564. # line 232 "Expressions.puma"
  565.    GetIntConstValue (exp->OP_EXP.OPND1, & yyV1, & yyV2);
  566. # line 233 "Expressions.puma"
  567.    if (! ((yyV1))) goto yyL5;
  568.   {
  569. # line 234 "Expressions.puma"
  570.    ResolveExpression (exp->OP_EXP.OPND2, & yyV3, & yyV4, & yyV5, & yyV6);
  571. # line 235 "Expressions.puma"
  572.    if (! ((yyV3))) goto yyL5;
  573.   }
  574.   }
  575.    * found = true;
  576.    * a = yyV2 * yyV4;
  577.    * b = yyV2 * yyV5;
  578.    * var = yyV6;
  579.    return;
  580.  }
  581. yyL5:;
  582.  
  583. # line 238 "Expressions.puma"
  584.  {
  585.   bool yyV1;
  586.   int yyV2;
  587.   bool yyV3;
  588.   int yyV4;
  589.   int yyV5;
  590.   tTree yyV6;
  591.   {
  592. # line 239 "Expressions.puma"
  593.    GetIntConstValue (exp->OP_EXP.OPND2, & yyV1, & yyV2);
  594. # line 240 "Expressions.puma"
  595.    if (! ((yyV1))) goto yyL6;
  596.   {
  597. # line 241 "Expressions.puma"
  598.    ResolveExpression (exp->OP_EXP.OPND1, & yyV3, & yyV4, & yyV5, & yyV6);
  599. # line 242 "Expressions.puma"
  600.    if (! ((yyV3))) goto yyL6;
  601.   }
  602.   }
  603.    * found = yyV3 && yyV1;
  604.    * a = yyV2 * yyV4;
  605.    * b = yyV2 * yyV5;
  606.    * var = yyV6;
  607.    return;
  608.  }
  609. yyL6:;
  610.  
  611.   }
  612.   break;
  613.   case kOP1_EXP:
  614.   if (exp->OP1_EXP.EXP_OP1->Kind == kOP1_SIGN) {
  615. # line 245 "Expressions.puma"
  616.  {
  617.   bool yyV1;
  618.   int yyV2;
  619.   int yyV3;
  620.   tTree yyV4;
  621.   {
  622. # line 246 "Expressions.puma"
  623.    ResolveExpression (exp->OP1_EXP.OPND, & yyV1, & yyV2, & yyV3, & yyV4);
  624. # line 247 "Expressions.puma"
  625.    if (! ((yyV1))) goto yyL7;
  626.   }
  627.    * found = yyV1;
  628.    * a = - yyV2;
  629.    * b = - yyV3;
  630.    * var = yyV4;
  631.    return;
  632.  }
  633. yyL7:;
  634.  
  635.   }
  636.   break;
  637.   case kVAR_EXP:
  638. # line 250 "Expressions.puma"
  639.    * found = true;
  640.    * a = 1;
  641.    * b = 0;
  642.    * var = exp->VAR_EXP.V;
  643.    return;
  644.  
  645.   case kVAR_PARAM:
  646. # line 253 "Expressions.puma"
  647.    * found = true;
  648.    * a = 1;
  649.    * b = 0;
  650.    * var = exp->VAR_PARAM.V;
  651.    return;
  652.  
  653.   case kUSED_VAR:
  654. # line 256 "Expressions.puma"
  655.    * found = true;
  656.    * a = 1;
  657.    * b = 0;
  658.    * var = exp;
  659.    return;
  660.  
  661.   case kINDEXED_VAR:
  662. # line 259 "Expressions.puma"
  663.    * found = true;
  664.    * a = 1;
  665.    * b = 0;
  666.    * var = exp;
  667.    return;
  668.  
  669.   case kLOOP_VAR:
  670. # line 262 "Expressions.puma"
  671.    * found = true;
  672.    * a = 1;
  673.    * b = 0;
  674.    * var = exp;
  675.    return;
  676.  
  677.   }
  678.  
  679. # line 265 "Expressions.puma"
  680.    * found = false;
  681.    * a = 0;
  682.    * b = 0;
  683.    * var = NoTree;
  684.    return;
  685.  
  686. ;
  687. }
  688.  
  689. static void MergeVars
  690. # if defined __STDC__ | defined __cplusplus
  691. (register int a1, register tTree v1, register int a2, register tTree v2, register bool * ok, register tTree * var)
  692. # else
  693. (a1, v1, a2, v2, ok, var)
  694.  register int a1;
  695.  register tTree v1;
  696.  register int a2;
  697.  register tTree v2;
  698.  register bool * ok;
  699.  register tTree * var;
  700. # endif
  701. {
  702.   if (equalint (a1, 0)) {
  703. # line 271 "Expressions.puma"
  704.    * ok = true;
  705.    * var = v2;
  706.    return;
  707.  
  708.   }
  709.   if (equalint (a2, 0)) {
  710. # line 274 "Expressions.puma"
  711.    * ok = true;
  712.    * var = v1;
  713.    return;
  714.  
  715.   }
  716. # line 277 "Expressions.puma"
  717.   {
  718. # line 278 "Expressions.puma"
  719.    if (! ( EqualExpression (v1, v2)  == true)) goto yyL3;
  720.   }
  721.    * ok = true;
  722.    * var = v1;
  723.    return;
  724. yyL3:;
  725.  
  726. # line 281 "Expressions.puma"
  727.    * ok = false;
  728.    * var = NoTree;
  729.    return;
  730.  
  731. ;
  732. }
  733.  
  734. bool EqualExpression
  735. # if defined __STDC__ | defined __cplusplus
  736. (register tTree e1, register tTree e2)
  737. # else
  738. (e1, e2)
  739.  register tTree e1;
  740.  register tTree e2;
  741. # endif
  742. {
  743. # line 293 "Expressions.puma"
  744.  {
  745.   bool found;
  746.   int val1;
  747.   int val2;
  748.   {
  749. # line 295 "Expressions.puma"
  750.  
  751. # line 296 "Expressions.puma"
  752.  
  753. # line 297 "Expressions.puma"
  754.  
  755. # line 299 "Expressions.puma"
  756.  GetIntConstValue (e1, &found, &val1);
  757. # line 300 "Expressions.puma"
  758.    if (! ((found))) goto yyL1;
  759.   {
  760. # line 301 "Expressions.puma"
  761.  GetIntConstValue (e2, &found, &val2);
  762. # line 302 "Expressions.puma"
  763.    if (! ((found))) goto yyL1;
  764.   {
  765. # line 303 "Expressions.puma"
  766.    if (! ((val1 == val2))) goto yyL1;
  767.   }
  768.   }
  769.   }
  770.    return true;
  771.  }
  772. yyL1:;
  773.  
  774.  
  775.   switch (e1->Kind) {
  776.   case kSLICE_EXP:
  777.   if (e2->Kind == kSLICE_EXP) {
  778. # line 306 "Expressions.puma"
  779.   {
  780. # line 307 "Expressions.puma"
  781.    if (! (EqualExpression (e1->SLICE_EXP.START, e2->SLICE_EXP.START))) goto yyL2;
  782.   {
  783. # line 308 "Expressions.puma"
  784.    if (! (EqualExpression (e1->SLICE_EXP.STOP, e2->SLICE_EXP.STOP))) goto yyL2;
  785.   {
  786. # line 309 "Expressions.puma"
  787.    if (! (EqualExpression (e1->SLICE_EXP.INC, e2->SLICE_EXP.INC))) goto yyL2;
  788.   }
  789.   }
  790.   }
  791.    return true;
  792. yyL2:;
  793.  
  794.   }
  795.   break;
  796.   case kDUMMY_EXP:
  797.   if (e2->Kind == kDUMMY_EXP) {
  798. # line 312 "Expressions.puma"
  799.    return true;
  800.  
  801.   }
  802.   break;
  803.   case kVAR_EXP:
  804.   if (e2->Kind == kVAR_EXP) {
  805. # line 315 "Expressions.puma"
  806.   {
  807. # line 316 "Expressions.puma"
  808.    if (! (EqualExpression (e1->VAR_EXP.V, e2->VAR_EXP.V))) goto yyL4;
  809.   }
  810.    return true;
  811. yyL4:;
  812.  
  813.   }
  814.   break;
  815.   case kUSED_VAR:
  816.   if (e2->Kind == kUSED_VAR) {
  817. # line 319 "Expressions.puma"
  818.   {
  819. # line 320 "Expressions.puma"
  820.    if (! (EqualExpression (e1->USED_VAR.VARNAME, e2->USED_VAR.VARNAME))) goto yyL5;
  821.   }
  822.    return true;
  823. yyL5:;
  824.  
  825.   }
  826.   break;
  827.   case kLOOP_VAR:
  828.   if (e2->Kind == kLOOP_VAR) {
  829. # line 323 "Expressions.puma"
  830.   {
  831. # line 324 "Expressions.puma"
  832.    if (! (EqualExpression (e1->LOOP_VAR.LOOP_VARNAME, e2->LOOP_VAR.LOOP_VARNAME))) goto yyL6;
  833.   }
  834.    return true;
  835. yyL6:;
  836.  
  837.   }
  838.   break;
  839.   case kVAR_OBJ:
  840.   if (e2->Kind == kVAR_OBJ) {
  841. # line 327 "Expressions.puma"
  842.   {
  843. # line 329 "Expressions.puma"
  844.    if (! (e1->VAR_OBJ.Ident == e2->VAR_OBJ.Ident)) goto yyL7;
  845.   }
  846.    return true;
  847. yyL7:;
  848.  
  849.   }
  850.   break;
  851.   case kOP_EXP:
  852.   if (e2->Kind == kOP_EXP) {
  853. # line 332 "Expressions.puma"
  854.   {
  855. # line 334 "Expressions.puma"
  856.    if (! (e1->OP_EXP.EXP_OP -> Kind == e2->OP_EXP.EXP_OP -> Kind)) goto yyL8;
  857.   {
  858. # line 335 "Expressions.puma"
  859.    if (! (EqualExpression (e1->OP_EXP.OPND1, e2->OP_EXP.OPND1))) goto yyL8;
  860.   {
  861. # line 336 "Expressions.puma"
  862.    if (! (EqualExpression (e1->OP_EXP.OPND2, e2->OP_EXP.OPND2))) goto yyL8;
  863.   }
  864.   }
  865.   }
  866.    return true;
  867. yyL8:;
  868.  
  869.   }
  870.   break;
  871.   case kOP1_EXP:
  872.   if (e2->Kind == kOP1_EXP) {
  873. # line 339 "Expressions.puma"
  874.   {
  875. # line 341 "Expressions.puma"
  876.    if (! (e1->OP1_EXP.EXP_OP1 -> Kind == e2->OP1_EXP.EXP_OP1 -> Kind)) goto yyL9;
  877.   {
  878. # line 342 "Expressions.puma"
  879.    if (! (EqualExpression (e1->OP1_EXP.OPND, e2->OP1_EXP.OPND))) goto yyL9;
  880.   }
  881.   }
  882.    return true;
  883. yyL9:;
  884.  
  885.   }
  886.   break;
  887.   }
  888.  
  889.   return false;
  890. }
  891.  
  892. int IsVarInExp
  893. # if defined __STDC__ | defined __cplusplus
  894. (register tIdent name, register tTree exp)
  895. # else
  896. (name, exp)
  897.  register tIdent name;
  898.  register tTree exp;
  899. # endif
  900. {
  901. # line 353 "Expressions.puma"
  902.  
  903. int c;
  904.  
  905.  
  906.   switch (exp->Kind) {
  907.   case kVAR_OBJ:
  908. # line 357 "Expressions.puma"
  909.   {
  910. # line 358 "Expressions.puma"
  911.    if (! (name == exp->VAR_OBJ.Ident)) goto yyL1;
  912.   }
  913.    return 1;
  914. yyL1:;
  915.  
  916. # line 362 "Expressions.puma"
  917.    return 0;
  918.  
  919.   case kUSED_VAR:
  920. # line 366 "Expressions.puma"
  921.    return IsVarInExp (name, exp->USED_VAR.VARNAME);
  922.  
  923.   case kLOOP_VAR:
  924. # line 370 "Expressions.puma"
  925.    return IsVarInExp (name, exp->LOOP_VAR.LOOP_VARNAME);
  926.  
  927.   case kINDEXED_VAR:
  928. # line 374 "Expressions.puma"
  929.    return (IsVarInExp (name, exp->INDEXED_VAR.IND_VAR) + IsVarInExp (name, exp->INDEXED_VAR.IND_EXPS));
  930.  
  931.   case kVAR_EXP:
  932. # line 378 "Expressions.puma"
  933.    return IsVarInExp (name, exp->VAR_EXP.V);
  934.  
  935.   case kBTE_LIST:
  936. # line 382 "Expressions.puma"
  937.    return (IsVarInExp (name, exp->BTE_LIST.Elem) + IsVarInExp (name, exp->BTE_LIST.Next));
  938.  
  939.   case kBTE_EMPTY:
  940. # line 386 "Expressions.puma"
  941.    return 0;
  942.  
  943.   case kSLICE_EXP:
  944. # line 390 "Expressions.puma"
  945.    return (IsVarInExp (name, exp->SLICE_EXP.START) + IsVarInExp (name, exp->SLICE_EXP.STOP) + IsVarInExp (name, exp->SLICE_EXP.INC));
  946.  
  947.   case kDUMMY_EXP:
  948. # line 395 "Expressions.puma"
  949.    return 0;
  950.  
  951.   case kCONST_EXP:
  952. # line 399 "Expressions.puma"
  953.    return 0;
  954.  
  955.   case kADDR:
  956. # line 403 "Expressions.puma"
  957.    return (IsVarInExp (name, exp->ADDR.E));
  958.  
  959.   case kOP_EXP:
  960. # line 407 "Expressions.puma"
  961.    return (IsVarInExp (name, exp->OP_EXP.OPND1) + IsVarInExp (name, exp->OP_EXP.OPND2));
  962.  
  963.   case kOP1_EXP:
  964. # line 411 "Expressions.puma"
  965.    return (IsVarInExp (name, exp->OP1_EXP.OPND));
  966.  
  967.   case kARRAY_EXP:
  968. # line 415 "Expressions.puma"
  969.    return IsVarInExp (name, exp->ARRAY_EXP.ELEMENTS);
  970.  
  971.   case kFUNC_CALL_EXP:
  972. # line 419 "Expressions.puma"
  973.    return IsVarInExp (name, exp->FUNC_CALL_EXP.FUNC_PARAMS);
  974.  
  975.   case kBTP_LIST:
  976. # line 423 "Expressions.puma"
  977.    return (IsVarInExp (name, exp->BTP_LIST.Elem) + IsVarInExp (name, exp->BTP_LIST.Next));
  978.  
  979.   case kBTP_EMPTY:
  980. # line 427 "Expressions.puma"
  981.    return 0;
  982.  
  983.   case kVAR_PARAM:
  984. # line 431 "Expressions.puma"
  985.    return (IsVarInExp (name, exp->VAR_PARAM.V));
  986.  
  987.   }
  988.  
  989. # line 435 "Expressions.puma"
  990.   {
  991. # line 436 "Expressions.puma"
  992.    printf ("Determination of IsVarInExp fails\n");
  993. # line 437 "Expressions.puma"
  994.    FileUnparse (stdout, exp);
  995. # line 438 "Expressions.puma"
  996.    WriteTree (stdout, exp);
  997. # line 439 "Expressions.puma"
  998.    exit (- 1);
  999.   }
  1000.    return 0;
  1001.  
  1002. }
  1003.  
  1004. tTree MakeNotExp
  1005. # if defined __STDC__ | defined __cplusplus
  1006. (register tTree e)
  1007. # else
  1008. (e)
  1009.  register tTree e;
  1010. # endif
  1011. {
  1012.   if (e->Kind == kOP1_EXP) {
  1013.   if (e->OP1_EXP.EXP_OP1->Kind == kOP1_NOT) {
  1014. # line 451 "Expressions.puma"
  1015.    return e->OP1_EXP.OPND;
  1016.  
  1017.   }
  1018.   }
  1019.   if (e->Kind == kOP_EXP) {
  1020.   if (e->OP_EXP.EXP_OP->Kind == kOP_LT) {
  1021. # line 455 "Expressions.puma"
  1022.   {
  1023. # line 456 "Expressions.puma"
  1024.    e->OP_EXP.EXP_OP = mOP_GE ();
  1025.   }
  1026.    return e;
  1027.  
  1028.   }
  1029.   if (e->OP_EXP.EXP_OP->Kind == kOP_LE) {
  1030. # line 460 "Expressions.puma"
  1031.   {
  1032. # line 461 "Expressions.puma"
  1033.    e->OP_EXP.EXP_OP = mOP_GT ();
  1034.   }
  1035.    return e;
  1036.  
  1037.   }
  1038.   if (e->OP_EXP.EXP_OP->Kind == kOP_GT) {
  1039. # line 465 "Expressions.puma"
  1040.   {
  1041. # line 466 "Expressions.puma"
  1042.    e->OP_EXP.EXP_OP = mOP_LE ();
  1043.   }
  1044.    return e;
  1045.  
  1046.   }
  1047.   if (e->OP_EXP.EXP_OP->Kind == kOP_GE) {
  1048. # line 470 "Expressions.puma"
  1049.   {
  1050. # line 471 "Expressions.puma"
  1051.    e->OP_EXP.EXP_OP = mOP_LT ();
  1052.   }
  1053.    return e;
  1054.  
  1055.   }
  1056.   if (e->OP_EXP.EXP_OP->Kind == kOP_EQ) {
  1057. # line 475 "Expressions.puma"
  1058.   {
  1059. # line 476 "Expressions.puma"
  1060.    e->OP_EXP.EXP_OP = mOP_NE ();
  1061.   }
  1062.    return e;
  1063.  
  1064.   }
  1065.   if (e->OP_EXP.EXP_OP->Kind == kOP_NE) {
  1066. # line 480 "Expressions.puma"
  1067.   {
  1068. # line 481 "Expressions.puma"
  1069.    e->OP_EXP.EXP_OP = mOP_NE ();
  1070.   }
  1071.    return e;
  1072.  
  1073.   }
  1074.   }
  1075. # line 485 "Expressions.puma"
  1076.    return mOP1_EXP (mOP1_NOT (), e);
  1077.  
  1078. }
  1079.  
  1080. void SliceIncrement
  1081. # if defined __STDC__ | defined __cplusplus
  1082. (register tTree yyP1, register bool * yyP3, register int * yyP2)
  1083. # else
  1084. (yyP1, yyP3, yyP2)
  1085.  register tTree yyP1;
  1086.  register bool * yyP3;
  1087.  register int * yyP2;
  1088. # endif
  1089. {
  1090.   if (yyP1->Kind == kSLICE_EXP) {
  1091. # line 491 "Expressions.puma"
  1092.  {
  1093.   bool found;
  1094.   int val;
  1095.   {
  1096. # line 492 "Expressions.puma"
  1097.  
  1098. # line 493 "Expressions.puma"
  1099.  
  1100. # line 494 "Expressions.puma"
  1101.  if (yyP1->SLICE_EXP.INC == NoTree)
  1102.         { found = true;
  1103.           val   = 1;
  1104.         }
  1105.        else if (yyP1->SLICE_EXP.INC->Kind == kDUMMY_EXP)
  1106.         { found = true;
  1107.           val   = 1;
  1108.         }
  1109.        else
  1110.         GetIntConstValue (yyP1->SLICE_EXP.INC, &found, &val);
  1111.  
  1112.   }
  1113.    * yyP3 = found;
  1114.    * yyP2 = val;
  1115.    return;
  1116.  }
  1117.  
  1118.   }
  1119. ;
  1120. }
  1121.  
  1122. tTree MakeSliceExp
  1123. # if defined __STDC__ | defined __cplusplus
  1124. (register tTree start, register tTree stop)
  1125. # else
  1126. (start, stop)
  1127.  register tTree start;
  1128.  register tTree stop;
  1129. # endif
  1130. {
  1131. # line 517 "Expressions.puma"
  1132.  {
  1133.   bool yyV1;
  1134.   int yyV2;
  1135.   bool yyV3;
  1136.   int yyV4;
  1137.   tTree exp;
  1138.   {
  1139. # line 518 "Expressions.puma"
  1140.    GetIntConstValue (start, & yyV1, & yyV2);
  1141. # line 519 "Expressions.puma"
  1142.    if (! (yyV1)) goto yyL1;
  1143.   {
  1144. # line 520 "Expressions.puma"
  1145.    GetIntConstValue (stop, & yyV3, & yyV4);
  1146. # line 522 "Expressions.puma"
  1147.  
  1148. # line 524 "Expressions.puma"
  1149.  if (yyV3)
  1150.         exp = mCONST_EXP (mINT_CONSTANT (yyV4 - yyV2 + 1));
  1151.       else if (yyV2 > 1)
  1152.  
  1153.         exp = mOP_EXP (mOP_MINUS(), stop, mCONST_EXP (mINT_CONSTANT(yyV2-1)));
  1154.       else if (yyV2 < 1)
  1155.  
  1156.         exp = mOP_EXP (mOP_PLUS(), stop, mCONST_EXP (mINT_CONSTANT(1-yyV2)));
  1157.       else
  1158.         exp = stop;
  1159.  
  1160.   }
  1161.   }
  1162.   {
  1163.    return exp;
  1164.   }
  1165.  }
  1166. yyL1:;
  1167.  
  1168. # line 538 "Expressions.puma"
  1169.  {
  1170.   tTree exp;
  1171.   {
  1172. # line 542 "Expressions.puma"
  1173.  
  1174. # line 544 "Expressions.puma"
  1175.  exp  = mOP_EXP (mOP_MINUS(), stop, start);
  1176.      exp  = mOP_EXP (mOP_PLUS (), exp, mCONST_EXP (mINT_CONSTANT(1)));
  1177.  
  1178.   }
  1179.   {
  1180.    return exp;
  1181.   }
  1182.  }
  1183.  
  1184. }
  1185.  
  1186. tTree AddConstant
  1187. # if defined __STDC__ | defined __cplusplus
  1188. (register tTree exp, register int c)
  1189. # else
  1190. (exp, c)
  1191.  register tTree exp;
  1192.  register int c;
  1193. # endif
  1194. {
  1195.   if (equalint (c, 0)) {
  1196. # line 562 "Expressions.puma"
  1197.    return exp;
  1198.  
  1199.   }
  1200. # line 566 "Expressions.puma"
  1201.  {
  1202.   bool yyV1;
  1203.   int yyV2;
  1204.   {
  1205. # line 567 "Expressions.puma"
  1206.    GetIntConstValue (exp, & yyV1, & yyV2);
  1207. # line 568 "Expressions.puma"
  1208.    if (! (yyV1 == true)) goto yyL2;
  1209.   }
  1210.   {
  1211.    return MakeConstant (c + yyV2);
  1212.   }
  1213.  }
  1214. yyL2:;
  1215.  
  1216.   if (exp->Kind == kOP_EXP) {
  1217.   if (exp->OP_EXP.EXP_OP->Kind == kOP_PLUS) {
  1218. # line 572 "Expressions.puma"
  1219.  {
  1220.   bool yyV1;
  1221.   int yyV2;
  1222.   {
  1223. # line 573 "Expressions.puma"
  1224.    GetIntConstValue (exp->OP_EXP.OPND1, & yyV1, & yyV2);
  1225. # line 574 "Expressions.puma"
  1226.    if (! (yyV1 == true)) goto yyL3;
  1227.   }
  1228.   {
  1229.    return AddConstant (exp->OP_EXP.OPND2, c + yyV2);
  1230.   }
  1231.  }
  1232. yyL3:;
  1233.  
  1234. # line 578 "Expressions.puma"
  1235.  {
  1236.   bool yyV1;
  1237.   int yyV2;
  1238.   {
  1239. # line 579 "Expressions.puma"
  1240.    GetIntConstValue (exp->OP_EXP.OPND2, & yyV1, & yyV2);
  1241. # line 580 "Expressions.puma"
  1242.    if (! (yyV1 == true)) goto yyL4;
  1243.   }
  1244.   {
  1245.    return AddConstant (exp->OP_EXP.OPND1, c + yyV2);
  1246.   }
  1247.  }
  1248. yyL4:;
  1249.  
  1250.   }
  1251.   if (exp->OP_EXP.EXP_OP->Kind == kOP_MINUS) {
  1252. # line 584 "Expressions.puma"
  1253.  {
  1254.   bool yyV1;
  1255.   int yyV2;
  1256.   {
  1257. # line 585 "Expressions.puma"
  1258.    GetIntConstValue (exp->OP_EXP.OPND2, & yyV1, & yyV2);
  1259. # line 586 "Expressions.puma"
  1260.    if (! (yyV1 == true)) goto yyL5;
  1261.   }
  1262.   {
  1263.    return AddConstant (exp->OP_EXP.OPND1, c - yyV2);
  1264.   }
  1265.  }
  1266. yyL5:;
  1267.  
  1268.   }
  1269.   }
  1270. # line 590 "Expressions.puma"
  1271.   {
  1272. # line 591 "Expressions.puma"
  1273.    if (! (c > 0)) goto yyL6;
  1274.   }
  1275.    return mOP_EXP (mOP_PLUS (), exp, mCONST_EXP (mINT_CONSTANT (c)));
  1276. yyL6:;
  1277.  
  1278. # line 595 "Expressions.puma"
  1279.   {
  1280. # line 596 "Expressions.puma"
  1281.    if (! (c < 0)) goto yyL7;
  1282.   }
  1283.    return mOP_EXP (mOP_MINUS (), exp, mCONST_EXP (mINT_CONSTANT (- c)));
  1284. yyL7:;
  1285.  
  1286.  yyAbort ("AddConstant");
  1287. }
  1288.  
  1289. tTree MakeConstant
  1290. # if defined __STDC__ | defined __cplusplus
  1291. (register int n)
  1292. # else
  1293. (n)
  1294.  register int n;
  1295. # endif
  1296. {
  1297. # line 602 "Expressions.puma"
  1298.   {
  1299. # line 603 "Expressions.puma"
  1300.    if (! ((n >= 0))) goto yyL1;
  1301.   }
  1302.    return mCONST_EXP (mINT_CONSTANT (n));
  1303. yyL1:;
  1304.  
  1305. # line 607 "Expressions.puma"
  1306.    return mOP1_EXP (mOP1_SIGN (), mCONST_EXP (mINT_CONSTANT (- n)));
  1307.  
  1308. }
  1309.  
  1310. void BeginExpressions ()
  1311. {
  1312. }
  1313.  
  1314. void CloseExpressions ()
  1315. {
  1316. }
  1317.